require_once( 'commandLine.inc' );
require_once( 'userFunctions.inc' );
-echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits.\n\n" );
+echo( "Remove Unused Accounts\nThis script will delete all users who have made no edits and uploaded no files.\n\n" );
# Check parameters
if( @$options['help'] ) {
echo( "Locating inactive users..." );
foreach( $users as $user ) {
if( $user != 1 ) { # Don't *touch* the first user account, ever
- if( CountEdits( $user, false ) == 0 ) {
- # User has no edits, mark them for deletion
+ if( CountEdits( $user, false ) == 0 && CountImages( $user, false ) == 0 ) {
+ # User has no edits or images, mark them for deletion
$del[] = $user;
$count++;
}
return( $count );
}
+/**
+ * Count the number of images the specified user has uploaded
+ *
+ * @param integer $user User ID
+ * @param bool $slave Whether or not a slave can be used
+ * @return integer
+ */
+function CountImages( $user, $slave = true ) {
+ $dbw =& wfGetDB( $slave ? DB_SLAVE: DB_MASTER );
+ # Count current images
+ $res = $dbw->select( 'image', 'COUNT(rev_id) AS count', array( 'img_user' => $user ) );
+ $row = $dbw->fetchObject( $res );
+ $count = $row->count;
+ # Count deleted edits
+ $res = $dbw->select( 'oldimage', 'COUNT(*) AS count', array( 'oi_user' => $user ) );
+ $row = $dbw->fetchObject( $res );
+ $count += $row->count;
+ # Done
+ return( $count );
+}
+
/**
* Retrieve all valid user IDs
*